package de.tum.in.eist.poll.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Foundation for all the webpages.
 * 
 * @author florian
 * 
 */
public abstract class Webpage {

	/**
	 * contains the PollService instance.
	 */
	private static PollServiceAsync pollService;

	/**
	 * Constructor
	 */
	public Webpage() {
	}

	/**
	 * Load the webpage.
	 */
	public abstract void loadWebsite();

	/**
	 * Reset Webpage content.
	 * 
	 * @param widget
	 *            Content to use for reset
	 */
	public final void setContent(final Widget widget) {
		RootPanel.get("gwt_content").clear();
		RootPanel.get("gwt_content").add(widget);
	}

	/**
	 * Creates the RPC Service class if it doesn't already exist.
	 * 
	 * @return RPC Service class
	 */
	public static PollServiceAsync getService() {
		if (pollService == null) {
			pollService = GWT.create(PollService.class);
		}
		return pollService;
	}
}
